package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.app.ListActivity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class MyListActivity extends ListActivity{
    private static final String TAG="list";
    Handler handler;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        String[] list_data={"one","two","three","测试数据"};
        ListAdapter adapter=new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1,list_data);
        setListAdapter(adapter);
        handler=new Handler(){
            public void handleMessage(Message msg){
                if(msg.what==5){
                    List<String> list2=(List<String>) msg.obj;
                    ListAdapter adapter=new ArrayAdapter<String>(MyListActivity.this, android.R.layout.simple_expandable_list_item_1,list2);
                    setListAdapter(adapter);
                }
                super.handleMessage(msg);
            }
        };
        MyTask myTask=new MyTask();
        myTask.setHandler(handler);
        Thread t=new Thread(myTask);//开启子线程
        t.start();//调用的是MyTask的run()方法
    }
}